package com.adong.crowd.service.impl;

import com.adong.crowd.entity.Role;
import com.adong.crowd.entity.RoleExample;
import com.adong.crowd.mapper.RoleMapper;
import com.adong.crowd.service.api.RoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;

    /**
     * 查询角色集合且分页
     */
    public PageInfo<Role> getRolePage(String keyword, Integer pageNum, Integer pageSize) {

        PageHelper.startPage(pageNum, pageSize);
        // 根据关键字查询出集合,为空也没关系
        List<Role> roles = roleMapper.selectRoleByKeyword(keyword);

        PageInfo<Role> rolePageInfo = new PageInfo<>(roles);

        return rolePageInfo;
    }

    /**
     * 添加数据
     *
     * @param role
     */
    @Override
    public void save(Role role) {

        roleMapper.insert(role);
    }

    @Override
    public void update(Role role) {
        roleMapper.updateByPrimaryKey(role);
    }

    @Override
    public void removeRole(List<Integer> roleList) {
        RoleExample example = new RoleExample();
        RoleExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(roleList);
        roleMapper.deleteByExample(example);
    }



}
